package com.ruoyi.system.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.DwTaskContent;
import com.ruoyi.system.service.IDwTaskContentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DwTask;
import com.ruoyi.system.service.IDwTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考核任务Controller
 * 
 * @author ruoyi
 * @date 2024-01-19
 */
@RestController
@RequestMapping("/system/task")
public class DwTaskController extends BaseController
{
    @Autowired
    private IDwTaskService dwTaskService;

    @Autowired
    private IDwTaskContentService dwTaskContentService;
    /**
     * 查询考核任务列表
     */
    @PreAuthorize("@ss.hasPermi('examine:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DwTask dwTask)
    {
        startPage();
        List<DwTask> list = dwTaskService.selectDwTaskList(dwTask);
        return getDataTable(list);
    }


    /**
     * 查询考核任务列表
     */
    @PreAuthorize("@ss.hasPermi('examine:task:list')")
    @GetMapping("/list/all")
    public AjaxResult listAll(DwTask dwTask)
    {
        return AjaxResult.success(dwTaskService.selectDwTaskList(dwTask));
    }
    /**
     * 根据id查询任务内容
     */
    @GetMapping(value = "/list/{taskId}")
    public AjaxResult dictType(@PathVariable Long taskId)
    {
        List<DwTaskContent> data = dwTaskContentService.selectDwTaskByTaskCode(taskId);
        if (StringUtils.isNull(data))
        {
            data = new ArrayList<>();
        }
        return AjaxResult.success(data);
    }


    /**
     * 导出考核任务列表
     */
    @PreAuthorize("@ss.hasPermi('examine:task:export')")
    @Log(title = "考核任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DwTask dwTask)
    {
        List<DwTask> list = dwTaskService.selectDwTaskList(dwTask);
        ExcelUtil<DwTask> util = new ExcelUtil<DwTask>(DwTask.class);
        util.exportExcel(response, list, "考核任务数据");
    }

    /**
     * 获取考核任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('examine:task:query')")
    @GetMapping(value = "/{taskCode}")
    public AjaxResult getInfo(@PathVariable("taskCode") Long taskCode)
    {
        return AjaxResult.success(dwTaskService.selectDwTaskByTaskCode(taskCode));
    }

    /**
     * 新增考核任务
     */
    @PreAuthorize("@ss.hasPermi('examine:task:add')")
    @Log(title = "考核任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DwTask dwTask)
    {
        return toAjax(dwTaskService.insertDwTask(dwTask));
    }

    /**
     * 修改考核任务
     */
    @PreAuthorize("@ss.hasPermi('examine:task:edit')")
    @Log(title = "考核任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DwTask dwTask)
    {
        return toAjax(dwTaskService.updateDwTask(dwTask));
    }

    /**
     * 删除考核任务
     */
    @PreAuthorize("@ss.hasPermi('examine:task:remove')")
    @Log(title = "考核任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskCodes}")
    public AjaxResult remove(@PathVariable Long[] taskCodes)
    {
        return toAjax(dwTaskService.deleteDwTaskByTaskCodes(taskCodes));
    }
}
